package com.fernfx.xingtan.common.network;

import java.io.File;
import java.util.Map;

/**
 */

public class SJJNetworkProxy implements ISJJNetworkProxy {

    ISJJNetworkProxy mProxy = new OkHttpProxy();

    private void setProxy(ISJJNetworkProxy proxy) {
        mProxy = proxy;
    }

    private static class ProxyHolder {
        private static SJJNetworkProxy sSJJNetworkProxy = new SJJNetworkProxy();
    }

    public static SJJNetworkProxy getInstance() {
        return ProxyHolder.sSJJNetworkProxy;
    }

    private SJJNetworkProxy() {
    }

    //region ISJJNetworkRequestProxy
    @Override
    public ISJJNetworkProxy addHeader(String name, String value) {
        mProxy.addHeader(name, value);
        return this;
    }

    @Override
    public ISJJNetworkProxy addQueryParam(String name, String value) {
        mProxy.addQueryParam(name, value);
        return this;
    }

    /**
     * 设置缓存过期时间
     *
     * @param maxAge 过期时间，0不走缓存
     * @return
     */
    @Override
    public ISJJNetworkProxy setMaxAge(int maxAge) {
        mProxy.setMaxAge(maxAge);
        return this;
    }

    @Override
    public ISJJNetworkProxy alreadyEncode(boolean alreadyEncode) {
        mProxy.alreadyEncode(alreadyEncode);
        return this;
    }

    @Override
    public void get(String url, Map<String, String> headers, IRequestCallback callback) {
        mProxy.get(url, headers, null, callback);
    }

    @Override
    public void get(String url, Map<String, String> headers, Map<String, String> queries, IRequestCallback callback) {
        mProxy.get(url, headers, queries, callback);
    }

    @Override
    public void post(String url, Map<String, String> headers, String jsonString, IRequestCallback callback) {
        mProxy.post(url, headers, jsonString, callback);
    }

    @Override
    public void post(String url, Map<String, String> headers, String jsonString, Map<String, String> queries, IRequestCallback callback) {
        mProxy.post(url, headers, jsonString, queries, callback);
    }


    @Override
    public void putImage(String url, Map<String, String> headers, File file, IRequestCallback callback) {
        mProxy.putImage(url, headers, file, callback);
    }

    @Override
    public void cancel() {
        mProxy.cancel();
    }
    //endregion
}
